package com.chinasoftinc.facommon.control;

import com.chinasoftinc.facommon.control.conversation.BleConnectState;

import java.util.HashMap;

/**
 * 支持链式添加数据的Map
 *
 * @since 2022-06-08
 */
public class DataMap extends HashMap<String, Object> {
    private static final String DEVICE_ID = "deviceId";
    private static final String CONNECT_STATE = "state";
    private static final String CODE = "code";
    private static final String MESSAGE = "message";
    private static final String DATA = "data";

    private final int code;

    private DataMap(int code) {
        super();
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public DataMap add(String key, Object value) {
        put(key, value);
        return this;
    }

    public DataMap withCode(int code) {
        return add(CODE, code);
    }

    public DataMap withMessage(String message) {
        return add(MESSAGE, message);
    }

    public DataMap withData(String data) {
        return add(DATA, data);
    }

    public DataMap withDeviceId(String deviceId) {
        return add(DEVICE_ID, deviceId);
    }

    public static DataMap newDataMap(int code) {
        return new DataMap(code);
    }

    @Override
    public String toString() {
        return "DataMap{" +
            "code=" + code +
            ", data=" + super.toString() +
            '}';
    }
}
